package com.naiterui.ehp.bs.recommend.service.impl;

import com.naiterui.ehp.bp.bo.im.PatientMsgSendParamBO;
import com.naiterui.ehp.bp.bo.patient.MsgPublishParamBO;
import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bs.recommend.bean.MedicationRecomDetail;
import com.naiterui.ehp.bs.recommend.remote.IPatientFeignClient;
import com.naiterui.ehp.bs.recommend.service.IRecomMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description 处方消息相关
 * @Author gongbaoqiang
 * @Date 2020/5/14 1:52 PM
 */
@Service
public class RecomMessageServiceImpl implements IRecomMessageService {

    @Autowired
    private IPatientFeignClient patientFeignClient;

    @Override
    public void sendPtMessage(Long doctorId, Long patientId, Long recomId,  List<MedicationRecomDetail> recomDetailList)
            throws BusinessException {
        String recomMsg = recomDetailList.stream().
                map(o -> o.getCommonName() + "\n【用法用量：" + o.getUsages() + "】\n").collect(Collectors.joining());

        patientFeignClient.sendRecommend(MsgPublishParamBO.builder()
                .doctorId(doctorId)
                .patientId(patientId)
                .msgType(PatientMsgSendParamBO.MsgType.RECOMMEND)
                .recomId(recomId)
                .recomMsg(recomMsg)
                .build());
    }
}
